package com.gj.planclass.controller;

import com.gj.planclass.model.PlanClassAddVo;
import com.gj.planclass.model.PlanClassServiceVo;
import com.gj.planclass.model.PlanClassUpdateStatusVo;
import com.gj.planclass.model.PlanClassUpdateVo;
import com.gj.planclass.service.PlanClassService;
import com.gj.subclass.model.SubClassAddVo;
import com.gj.utli.ResultBuilderVo;
import com.gj.utli.ResultVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by Tangyunhen on 2021-06-27.
 */
@RestController
@CrossOrigin
public class PlanClassController {
    @Autowired
    private PlanClassService planClassService;
    //分页查询
    @PostMapping("/planCategory/queryPage")
    public ResultVo queryPage(@RequestBody PlanClassServiceVo planClassServiceVo){
       return planClassService.queryPage(planClassServiceVo);
    }
   //添加
    @PostMapping("/planCategory/add")
    public ResultVo add(@RequestBody @Valid PlanClassAddVo planClassAddVo,BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return planClassService.add(planClassAddVo);

}
//修改            /planCategory/update
    @PostMapping("/planCategory/update")
    public ResultVo update(@RequestBody @Valid PlanClassUpdateVo planClassUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return planClassService.update(planClassUpdateVo);

    }
    //启用禁用/planCategory/updateStatus
    @PostMapping("/planCategory/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid PlanClassUpdateStatusVo planClassUpdateStatusVo,BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return planClassService.updateStatus(planClassUpdateStatusVo);

    }
    @GetMapping("seet")
    public ResultVo seet(@RequestParam("id")Integer id){
        if (id==null){
            return ResultBuilderVo.error("id不能为空");
        }
        return planClassService.seet(id);
    }

}
